<?
//require('JSON.php');


//$json = new Services_JSON();

//foreach($_POST as $key => $value) {
//	error_log(" $key => $value ");
//	
//	foreach ($value as $k => $v) {
//		error_log(" $k => $v ");
//		if( $k == 'items' ) {
//			foreach 
//		}
//	} 
//}

//$output = array ();
//
//$output['count'] 		= $_POST['sortable_list']['count'];
//$output['firstIndex'] 	= $_POST['sortable_list']['firstIndex'];
//$output['columns']		= array('Title(ID)');
//$output['items']		= $_POST['sortable_list']['items'];
error_log('start save JSON');

define (SQL,"INSERT INTO `menu_relations` (`parent_id` ,`child_id`) VALUES ('%s', '%s')");

foreach ($_POST['sortable_list']['items'] as $key => $value) {
	
	//error_log(" $key => $value ");
//	$output['items'][] = 
	addItem($value);
}

//$info = $json->encode($output);
//file_put_contents('test.js',$info);
//error_log($info);

error_log('end save JSON');

function addInfo($item) {
	
	$item['info'] = array('Page Title('.$item[id].')');
	/*
	if($item['children']) {
		foreach ($item['children'] as $k => $v) {
			$item['children']['items'] = addInfo($v);
		}
	}*/
	
	return $item; 
}

function addItem ($parent) {
	
//	$new = array();
	
//	"UPDATE `menu` SET "
	
//	$new[id] 	= $item[id];
//	$new[info]	= array("Page Title($item[id])");
	
	if($parent['children']) {
		foreach ($parent['children'] as $k => $child) {
//			$new['children'][] = addItem($v);
			error_log(sprintf(SQL,$parent['id'],$child['id']));

		}
	}
	
//	return $new;
}
?>